package com.sunjob.loginserver.service;

import com.sunjob.loginserver.config.RoleAuthInitConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Wangzurong
 * @create 2022-08-10 16:10
 */
@Service
public class RedisTemplateServiceImpl implements RedisTemplateService {
    @Autowired
    RoleAuthInitConfig roleAuthInitConfig;
    @Autowired
    RedisTemplate<String,Object> redisTemplate;
    @Override
    public Boolean flushRedis() {
        deleteRedis();
        loadRedis();
        return true;
    }

    @Override
    public Boolean loadRedis() {
        try {
            roleAuthInitConfig.run(null);
        }catch (Exception e){

        }
        return true;
    }

    @Override
    public Boolean deleteRedis() {
        Set<String> keys = redisTemplate.keys("*");
        redisTemplate.delete(keys);
        return true;
    }
}
